<template xmlns="http://www.w3.org/1999/html">
  <sea-data-table ref="tableObject" url="/sys/bulletin/page">
    <!--表头-->
    <sea-table-header slot="header">
      <!--标题栏-->
      <sea-table-title slot="title" title="系统公告管理" subtitle=""></sea-table-title>

      <!--按钮栏-->
      <template slot="buttons">
        <el-button plain size="small" title="新增" icon="fa fa-plus" @click="onAction('new')"></el-button>
      </template>
    </sea-table-header>

    <!-- 弹窗、抽屉 -->
    <template slot="drawer">
      <sea-dialog ref="create_dialog">
        <create ref="create"></create>
      </sea-dialog>
      <sea-dialog ref="modify_dialog">
        <modify ref="modify" :on-succeed="onSucceed"></modify>
      </sea-dialog>
    </template>

    <!--表头-->
    <template slot="columns">
      <el-table-column property="bulletinTitle" label="标题"></el-table-column>
      <el-table-column property="bulletinOwner" label="归属" width="180"></el-table-column>
      <sea-col-dictionary property="bulletinType" label="类型" width="180"
                  options="t_sys_bulletin.bulletin_type"></sea-col-dictionary>
      <el-table-column property="bulletinStatus" label="公告状态" width="180"></el-table-column>
      <el-table-column property="gmtPublic" label="发布日期" width="180"></el-table-column>
      <el-table-column property="gmtCreate" label="创建日期" width="180"></el-table-column>
      <el-table-column property="gmtModified" label="修改日期" width="180"></el-table-column>

      <!--操作栏-->
      <sea-table-actionbar width="180" :on-action="onAction" :buttons="buttons"></sea-table-actionbar>
    </template>
  </sea-data-table>
</template>

<script>

import create from "./create";
import modify from "./modify";

export default {
    components: {create, modify},
    data() {
        return {
            // 操作名称
            operation: undefined
            // 当前操作的行级对象
            , row_data: undefined
            // 操作栏
            , buttons: [
                {type: 'btn', evt: 'edit', label: '编辑', title: '编辑当前行'}
            ]
            // end--
        }
    },
    methods: {
        /**
         * 操作成功回调
         */
        onSucceed: function () {
            this.$refs.tableObject.reload();
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'new') {
                let dialog = {title: `新建`, fullscreen: true};
                this.$refs.create_dialog.open(dialog);
            } else if (evt === 'delete') {
                this.$layers.delete({
                    url: '/sys/bulletin/info'
                    , params: {id: row.id}
                }).then((ret) => {
                    if (ret.code === 0) {
                        this.$layers.succeed();
                    }
                });
            }else if (evt === 'edit') {
                let dialog = {title: `更新`, fullscreen: true};

                this.$refs.modify_dialog.open(dialog).then(() => {
                    this.$refs.form_modify.val(row);
                });
            }
        }
    }
}
</script>
